package com.starchen.optimalselection.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.starchen.optimalselection.common.mapper.AdvertiseMapper;
import com.starchen.optimalselection.common.mapper.NewProductMapper;
import com.starchen.optimalselection.common.mapper.RecommendProductMapper;
import com.starchen.optimalselection.common.mapper.SkuInfoMapper;
import com.starchen.optimalselection.common.model.Advertise;
import com.starchen.optimalselection.common.model.NewProduct;
import com.starchen.optimalselection.common.model.RecommendProduct;
import com.starchen.optimalselection.common.model.SkuInfo;
import com.starchen.optimalselection.web.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author daxilong
 * @date 2024/11/10 22:44
 */
@Service
public class HomeServiceImpl implements HomeService {

    @Autowired
    private AdvertiseMapper advertiseMapper;

    @Autowired
    private RecommendProductMapper recommendProductMapper;

    @Autowired
    private NewProductMapper newProductMapper;

    @Autowired
    private SkuInfoMapper skuInfoMapper;


    @Override
    public List<Advertise> getBannerList() {
        QueryWrapper<Advertise> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status",1);
        List<Advertise> list = advertiseMapper.selectList(queryWrapper);
        return list;
    }


    @Override
    public List<SkuInfo> getRecommendList() {
        QueryWrapper<RecommendProduct> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("recommend_status",1);
        List<RecommendProduct> recommendProductList = recommendProductMapper.selectList(queryWrapper);

        List<Long> ids = recommendProductList.stream().map( recommendProduct -> recommendProduct.getProductId()).collect(Collectors.toList());

        List<SkuInfo> skuInfoList = skuInfoMapper.selectBatchIds(ids);

        return skuInfoList;
    }

    @Override
    public List<SkuInfo> getNewList() {
        QueryWrapper<NewProduct> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("recommend_status",1);
        List<NewProduct> newProductList = newProductMapper.selectList(queryWrapper);

        List<Long> ids = newProductList.stream().map( product -> product.getProductId()).collect(Collectors.toList());

        List<SkuInfo> skuInfoList = skuInfoMapper.selectBatchIds(ids);

        return skuInfoList;
    }

}
